<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<h1>Redis Cache</h1>
<script type="text/javascript" src="${contextPath}/static/script/jquery/jquery-1.4.2.js"></script>
<style type="text/css">
    .valueFont {
        height: 30px;
        font-size: 11pt;
        font-weight: bold;
    }
</style>
<script type="text/javascript">

    function redoSchedule(triggerObj) {
        if (confirm("Do you redo Schedule ?")) {
            triggerObj.attr("disabled", "true");
            appendMsg(triggerObj, "<span>syncService is running</span>");
            $.ajax({
                type:"GET",
                url:"./redoSchedule.dhtml",
                dataType:"json",
                success:function (echo) {
                    triggerObj.attr("disabled", false);
                    appendMsg(triggerObj, echo.message);
                }
            });
        }
    }

    function appendMsg(triggerObj, msg) {
        triggerObj.parent().find("span:eq(0)").empty();
        triggerObj.parent().find("span:eq(0)").append(msg);
    }
    function searchHotel(triggerObj) {
        var propertyId = triggerObj.parent().find("input:eq(0)").val();
        var passport = triggerObj.parent().find("input:eq(1)").val();
        var action = './search/searchHotel.dhtml?hotelCondition.propertyId=' + propertyId + '&hotelCondition.passport=' + passport;
        submitRequest(action, triggerObj);
    }

    function searchRoomOccupancy(triggerObj) {
        var propertyId = triggerObj.parent().find("input:eq(0)").val();
        var start = triggerObj.parent().find("input:eq(1)").val();
        var end = triggerObj.parent().find("input:eq(2)").val();
        var roomTypeId = triggerObj.parent().find("input:eq(3)").val();
        var action = './search/searchRoomOccupancy.dhtml?roomOccupancyCondition.propertyId=' + propertyId
                + '&roomOccupancyCondition.start=' + start
                + '&roomOccupancyCondition.end=' + end
                + '&roomOccupancyCondition.roomTypeId=' + roomTypeId;
        submitRequest(action, triggerObj);
    }

    function searchRoomStay(triggerObj) {
        var propertyId = triggerObj.parent().find("input:eq(0)").val();
        var roomTypeId = triggerObj.parent().find("input:eq(1)").val();
        var start = triggerObj.parent().find("input:eq(2)").val();
        var end = triggerObj.parent().find("input:eq(3)").val();
        var action = './search/searchRoomStay.dhtml?roomStayCondition.propertyId=' + propertyId
                + '&roomStayCondition.roomTypeId=' + roomTypeId
                + '&roomStayCondition.start=' + start
                + '&roomStayCondition.end=' + end;
        submitRequest(action, triggerObj);
    }

    function searchRoomType(triggerObj) {
        var roomTypeId = triggerObj.parent().find("input:eq(0)").val();
        var action = './search/searchRoomType.dhtml?roomTypeCondition.roomTypeId=' + roomTypeId;
        submitRequest(action, triggerObj);
    }

    function searchRate(triggerObj) {
        var propertyId = triggerObj.parent().find("input:eq(0)").val();
        var start = triggerObj.parent().find("input:eq(1)").val();
        var adult = triggerObj.parent().find("input:eq(2)").val();
        var child = triggerObj.parent().find("input:eq(3)").val();
        var ratePlanId = triggerObj.parent().find("input:eq(4)").val();
        var roomTypeId = triggerObj.parent().find("input:eq(5)").val();
        var action = './search/searchRate.dhtml?rateCondition.propertyId=' + propertyId
                + '&rateCondition.start=' + start
                + '&rateCondition.adult=' + adult
                + '&rateCondition.child=' + child
                + '&rateCondition.ratePlanId=' + ratePlanId
                + '&rateCondition.roomTypeId=' + roomTypeId;
        submitRequest(action, triggerObj);
    }

    function submitRequest(action, triggerObj) {
        triggerObj.parent().find("span:eq(1)").empty();
        triggerObj.parent().find('textarea:eq(0)').val('');
        $.ajax({
            type:"GET",
            url:action,
            dataType:"json",
            success:function (echo) {
                if (echo.result) {
                    triggerObj.parent().find('textarea:eq(0)').addClass("valueFont");
                    triggerObj.parent().find('textarea:eq(0)').val(echo.message);
                } else {
                    showErrorLog(triggerObj, echo.message);
                }
            }
        });
    }
    function showErrorLog(triggerObj, message) {
        var spanObj = triggerObj.parent().find("span:eq(1)");
        spanObj.empty();
        spanObj.attr("style", "color:red");
        spanObj.append(message);
    }
</script>
<s:if test="syncFtpFiles!=null && !syncFtpFiles.isEmpty()">
    <div class="main">
        <div align="right">
            <div>
                <s:iterator value="syncFtpFiles">
                    <ul>
                        <li><s:property/></li>
                    </ul>
                </s:iterator>
            </div>
            <span></span>
            <input type="button" value="Execute Schedule" onclick="redoSchedule($(this));" class="common_button">
        </div>
    </div>
</s:if>

<div class="main">
    <span class="title">Hotel: </span>
    <label>Hotel Id：<input type="text" size="10"/></label>
    <label>Derby Hotel Code：<input type="text" size="40"/></label>
    <br>
    <label><textarea rows="1" cols="50" class="valueFont"></textarea></label>
    <br>
    <label>HotelId:Passport:Name:Status</label>
    <br>
    <input name="Hotel" type="button" value="Search" onclick="searchHotel($(this));" class="common_button"/>
    <br>
    <span></span>
</div>

<div class="main">
    <span class="title">RoomOccupancy: </span>
    <label>Hotel Id：<input type="text" size="10"/></label>

    <label>Start：<input type="text" size="15"/></label>

    <label>End：<input type="text" size="15"/></label>

    <label>RoomType：<input type="text" size="10"/></label>
    <br>

    <label><textarea rows="1" cols="30" class="valueFont"></textarea></label>
    <br>
    <label>Start:End:RoomTypeID:MinAdults:MaxAdults:MinOccupancy:MaxOccupancy:MaxChildren:MaxAdultsWithChildren</label>
    <br>
    <input type="button" value="Search" onclick="searchRoomOccupancy($(this));" class="common_button"/>
    <br>
    <span></span>
</div>

<div class="main">
    <span class="title">RoomStay: </span>
    <label>Hotel Id：<input type="text" size="10">*</label>

    <label>RoomType：<input type="text" size="15">*</label>

    <label>Start：<input type="text" size="15"></label>

    <label>End：<input type="text" size="15"></label>
    <br>
    <label><textarea rows="1" cols="30" class="valueFont"></textarea></label>
    <br>
    <label>Start:End:MinStay:MaxStay:DayType</label>
    <br>
    <input type="button" value="Search" onclick="searchRoomStay($(this));" class="common_button"/>
    <br>
    <span></span>
</div>

<div class="main">
    <span class="title">RoomType: </span>
    <label>RoomType：<input type="text" size="20">*</label>
    <br>
    <label><textarea rows="1" cols="50" class="valueFont"></textarea></label>
    <br>
    <label>RoomTypeCode:Description</label>
    <br>
    <input type="button" value="Search" onclick="searchRoomType($(this));" class="common_button"/>
    <br>
    <span></span>
</div>

<div class="main">
    <span class="title">Rate: </span>
    <label>Hotel Id：<input type="text" size="10">*</label>

    <label>Start：<input type="text" size="15">*</label>

    <label>Adult：<input type="text" size="3">*</label>

    <label>Child：<input type="text" size="3">*</label>

    <label>RatePlan：<input type="text" size="10"></label>

    <label>RoomType：<input type="text" size="10"></label>

    <label><textarea rows="1" cols="50" class="valueFont"></textarea></label>
    <br>
    <label>RatePlan:RoomTypeId:Rate</label>
    <br>
    <input type="button" value="Search" onclick="searchRate($(this));" class="common_button"/>
    <br>
    <span></span>
</div>
